<?php


namespace App\Transformers\Member;


use App\Models\MemberCard;
use App\Models\User;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class MemberCardTransFormer extends TransformerAbstract
{
    protected $availableIncludes = ['batch','user'];
    public function transform(MemberCard $data)
    {
    return [
         'id'=>$data->id,
         'card_batch_id' =>$data->card_batch_id ?? '',
         'user_id' =>$data->user_id ?? '',
         'card_number' =>$data->card_number ?? '',
         'use_time' =>$data->use_time ?? '',
         'status' =>$data->status ?? '',
         'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
         'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
    ];

    }

    /**
     * 会员卡所属批次
     */
    public function includeBatch(MemberCard $memberCard){
        return $this->item($memberCard->batch,new MemberCardBatchTransFormer());
    }

    /**
     * 会员卡所包含的用户信息
     */
    public function includeUser(MemberCard $memberCard){
        return $this->item($memberCard->user,new UserTransformer());
    }
}
